<?php

declare(strict_types=1);

namespace Plugin\Attractions\AttractionManagement\Controller;

use Common\CommonController;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\Swagger\Annotation\HyperfServer;
use Plugin\Attractions\AttractionManagement\Repository\AttractionTagsRepository;

#[HyperfServer(name: 'http')]
#[Controller('attractions/attraction-management')]
class TagController extends CommonController
{ 
    #[Inject]
    private AttractionTagsRepository $repository;

    #[GetMapping('listTags')]
    public function listAttractions()
    {
        $data = $this->valid([
            'name' => 'string|max:64',
            'page' => 'integer|min:1',
            'pageSize' => 'integer:min:1|max:100',
        ], []);
        return $this->success($this->repository->showListPage($data));
    }

    #[PostMapping('addTag')]
    public function addTag()
    {
        $data = $this->valid([
            'name' => 'required|string|max:64'
        ], []);
        return $this->success($this->repository->create($data));
    }

    #[GetMapping('deleteTag')]
    public function deleteTag()
    {
        $data = $this->valid(['id' => 'required|regex:/^\d+(,\d+)*$/'], []);
        $ids = explode(',', $data['id']);
        return $this->success($this->repository->deleteById($ids));
    }
}